<?php include_once($_SERVER['DOCUMENT_ROOT']."/controller/common/common_setting_unit.php");         // 引入通用的设置文件 ?>
<?php include_once($_SERVER['DOCUMENT_ROOT']."/controller/common/module/head.php"); // 引入通用的头部 ?>
<?php include_once ("controller/data_add.php"); ?>
<?php include_once ("module/mod-nkeditor.php"); ?>
<?php include_once("controller/model/language.php");//属性名字 ?>


<?php include_once("function.php"); ?>
<?php include_once("term-select-list-function.php"); ?>
<?php include_once("brand-select-list-function.php"); ?>
<link href="asset/css/style.css"      rel="stylesheet" type="text/css"/>



<body>

<!--顶部栏-->
<div id="topbar"> <?php include $_SERVER['DOCUMENT_ROOT'] . '/controller/common/module/topbar.php'; ?></div>

<!--容器-->
<div id="container" class="<? echo $now_extender ?>">

    <!--侧边栏-->
    <div id="sidebar"><?php include $_SERVER['DOCUMENT_ROOT'] . '/controller/common/module/sidebar.php'; ?></div>





    <?
    //==============================================================================
    //这里开始才是平常开发需要注重的部分，其余的基本不用理会
    //==============================================================================
    ?>


    <div id="content" class="layui-form detail">

        <!--标题设定-->
        <?php $page_title='添加资料';?>
        <?php include $_SERVER['DOCUMENT_ROOT']. '/controller/common/module/mod-page-title.php'; ?>





<div class="detail-box  <? echo $system_part ?>">
<div class="detail-boxes">
<ul class="detail-boxing">

<form id="detail_form"
      name="uploadfile"
      method="post"
      onsubmit="return checkRequired(detail_name);"
      action="detail-add-function.php?sys_part=<? echo $system_part ?>"
      enctype="multipart/form-data"
      class="layui-form-pane">




    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <ul class="layui-tab-title">
            <li class="layui-this">基本内容</li>
            <li>SEO优化</li>
            <li>媒体附件</li>
            <li>权限分配</li>
            <li>关联内容</li>
            <li>其他设置</li>
        </ul>
        <div class="layui-tab-content" style="height: 100px;">
            <div class="layui-tab-item layui-show">
                <? include("module/mod-add-main.php");?>

            </div>
            <div class="layui-tab-item">
                <? include("module/mod-seo.php");?>
            </div>
            <div class="layui-tab-item">
                <? include("module/mod-add-media.php");?>

            </div>
            <div class="layui-tab-item">
                <? include("module/mod-add-permission.php");?>
            </div>
            <div class="layui-tab-item">
                <? include("module/mod-add-connection.php");?>
            </div>
            <div class="layui-tab-item">
                <? include("module/mod-add-other.php");?>
            </div>
        </div>
    </div>





	
    <div class="more_link" style="display:none">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;" id="content4">
            <legend>关联板块</legend>
        </fieldset>
        <br/>
    
    
        <div class="">
                      <?php 
                      $type_list  = select_lines_all_items($table=$table_Prefix.'plate','nid desc'," link_menu = 1 " )
                      ?>
                      <div class="layui-form-item">
                        <label class="layui-form-label">搜索关联文章类型</label>
                        <div class="layui-input-block">
                          <?php foreach($type_list as $val){?>
                          <input name="article_type[]" value="<?php echo $val['mid']?>" title="<?php echo $val['name']?>" type="checkbox">
                          <?php }?>
                          <br />
                          <br />
                          <div class="layui-btn layui-btn-sm layui-btn-warm search_btn">搜索相关内容</div> 
                        </div>
                        
                      </div>
                      
                      <div style="position:relative;">
    
                            <div id="test4" class="demo-transfer"></div>
                          	<div class="buttonDiv">
                            <button type="button" class="layui-btn layui-btnUpDownmax upMaxBtn" onclick="moveUpMax('test4')"> 
                                <i class="layui-icon">&#xe619;</i>
                                <i class="layui-icon">&#xe619;</i>
                            </button>
                            <button type="button" class="layui-btn layui-btnUpDown upBtn" onclick="moveUp('test4')"> 
                                <i class="layui-icon">&#xe619;</i>
                            </button>
                            <button type="button" class="layui-btn layui-btnUpDown downBtn" onclick="moveDown('test4')">
                                <i class="layui-icon">&#xe61a;</i>
                            </button>
                            <button type="button" class="layui-btn layui-btnUpDownmax downMaxBtn" onclick="moveDownMax('test4')">
                                <i class="layui-icon">&#xe61a;</i>
                                <i class="layui-icon">&#xe61a;</i>
                            </button>
                            
                        </div>
                      </div>
                </div>
	</div>
	 <hr/>
     
     <div class="attr_box" style=" display:none">
     	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;" id="content4">
            <legend>产品属性</legend>
        </fieldset>
        <br/>
     	<table width="100%" id="gallery-table" align="center">
          
          <tr>
            <td>
              <a href="javascript:;" onclick="addImg(this)">[+]</a>
               图片标题  <input type="text" name="img_title[]" size="20" />
               图片描述  <input type="text" name="img_desc[]" size="20" />
               上传图片  <input type="file" name="img_url[]" />
               图片价格  <input type="text"  style="color:#aaa;" name="img_price[]"/>
            </td>
          </tr>
          
        </table>
     </div>

    <div class=" goods_attr_box" style="display:none;"  >
        <?php
        $goods_list = select_lines_all_items($table_Prefix . "detail", ' nid  desc ' , " belong = 'product' and publish = 1 ");

        foreach($goods_list as $key=>$val){
            $new_goods_list[$key]['title'] = $val['name'];
            $new_goods_list[$key]['value'] = $val['nid'];
        }

        $json_goods_list = json_encode($new_goods_list);


        ?>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;" id="content5">
            <legend>关联商品</legend>
        </fieldset>
        <br/>


        <div style="position:relative;">
            <div id="test5" class="demo-transfer"></div>
            <div class="buttonDiv">
                <button type="button" class="layui-btn layui-btnUpDownmax upMaxBtn" onclick="moveUpMax('test5')">
                    <i class="layui-icon">&#xe619;</i>
                    <i class="layui-icon">&#xe619;</i>
                </button>
                <button type="button" class="layui-btn layui-btnUpDown upBtn" onclick="moveUp('test5')">
                    <i class="layui-icon">&#xe619;</i>
                </button>
                <button type="button" class="layui-btn layui-btnUpDown downBtn" onclick="moveDown('test5')">
                    <i class="layui-icon">&#xe61a;</i>
                </button>
                <button type="button" class="layui-btn layui-btnUpDownmax downMaxBtn" onclick="moveDownMax('test5')">
                    <i class="layui-icon">&#xe61a;</i>
                    <i class="layui-icon">&#xe61a;</i>
                </button>

            </div>
        </div>
    </div>

    <div class="function">
        <input type="hidden" name="detail_attr" id="detail_attr" />
        <input type="hidden" name="goods_attr" id="goods_attr" />
        <input type="hidden" name="cat_list_json" id="cat_list_json" />
        <input type="hidden" name="brand_list_json" id="brand_list_json" />
        
        <button class="layui-btn "  lay-submit type="button" lay-filter="formSub">立即提交</button>
        <input type="reset" class="layui-btn" value="重置"/>
		
        <input name="sys_part" type="hidden" value="<? echo $system_part ?>"/>
        <input name="nowpageid" type="hidden" value="<? echo $_REQUEST['nowpageid'] ?>"/>
        <input name="sortby" type="hidden" value="<? echo $_REQUEST['sortby'] ?>"/>
        <input name="term_nid" type="hidden" value="<? echo $_REQUEST['term_nid'] ?>"/>


        <a 	class="layui-btn layui-btn-normal" href="#content1" style="margin-left: 35px">基本信息</a>
        <a 	class="layui-btn layui-btn-normal" href="#content2">SEO设置</a>
        <a 	class="layui-btn layui-btn-normal" href="#content3">更多资料</a>
        <a 	class="layui-btn layui-btn-normal more_link" href="#content4" style="display:none">关联板块</a>

        <a href="javascript:;" class="layui-btn layui-bg-red layui-icon layui-icon-top go_top"></a>
    </div>


</form>
</ul>
</div>
</div>

<!--content端點01-->
</div>
<!--maincontent端點01-->
<br class="clearfloat"/>
</div>
<!--container端點01-->
</div>



<script>
    var filePath_ = "/uploadfiles/" + "<?php echo $theme_folder?>" + "/";
    var videoUploadSwitch_ = false;
var Browser = new Object();

Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox") != - 1);
Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != - 1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != - 1);


 function addImg(obj)
  {
      var src  = obj.parentNode.parentNode;
      var idx  = rowindex(src);
      var tbl  = document.getElementById('gallery-table');
      var row  = tbl.insertRow(idx + 1);
      var cell = row.insertCell(-1);
      cell.innerHTML = src.cells[0].innerHTML.replace(/(.*)(addImg)(.*)(\[)(\+)/i, "$1removeImg$3$4-");
  }

  /**
   * 鍒犻櫎鍥剧墖涓婁紶
   */
  function removeImg(obj)
  {
      var row = rowindex(obj.parentNode.parentNode);
      var tbl = document.getElementById('gallery-table');

      tbl.deleteRow(row);
  }
  
  function rowindex(tr)
{
  if (Browser.isIE)
  {
    return tr.rowIndex;
  }
  else
  {
    table = tr.parentNode.parentNode;
    for (i = 0; i < table.rows.length; i ++ )
    {
      if (table.rows[i] == tr)
      {
        return i;
      }
    }
  }
}

$('.search_btn').click(
	function(){
		
		/*$.each($("input[name='article_type[]']"), function(i,val){ 
			
			 alert(val.name);
			 alert(val.value);  
		});*/
		 search_val = '';
		 $.each($("input[name='article_type[]']:checked"),function(){
              select_val = $(this).val();
			  if(search_val.length > 0){
				 search_val=search_val+','+select_val;
			  }
			  else{
				 search_val=select_val;
			  }
        });  
		
			$.ajax({
			type:"POST",
			url:"ajax_search_detail.php?act=search_detail",
			dateType:"json",
			data:{"val":search_val},
			dataType:"json",
			beforeSend: function () {
				
				$('.search_btn').attr({ disabled: "disabled" });
				
			   index =  layer.msg('正在查询中，请稍等', {
				  icon: 16,
				  shade:true,
				  time:10000,
				  shade: [0.8, '#393D49']
				},function(){
					
				});
				
			
			 }, 
			success:function(data){				
				if(data.error == 1){
					
					var msg_box = layer.msg(data.message, {
					  icon: 5,
					  shade:true,
					  time:1000,
					  shade: [0.8, '#393D49']
					});
					//
				}	
				else{
					layui.use(['transfer', 'layer', 'util'], function(){
					  var $ = layui.$
					  ,transfer = layui.transfer
					  ,layer = layui.layer
					  ,util = layui.util;
					  
					   
					  //模拟数据
					  var data1 = data.content
					  
					   transfer.reload('detail_attr_list', {
						  data: data1
						});
						
					});
					
				}
			},
			complete: function (XHR, TS) {layer.close(index);    XHR = null ; $('.search_btn').removeAttr("disabled"); } ,
			
		})

	}
)





  
 layui.use(['transfer', 'layer', 'util', 'form', 'tree'], function(){
	  var $ = layui.$
	  ,transfer = layui.transfer
	  ,layer = layui.layer
	  ,util = layui.util
	  ,tree = layui.tree
	  ,form = layui.form;
	   
	
	var data1 = []  //显示搜索框
	transfer.render({
			elem: '#test4'
			,data: data1
			,title: ['全选', '全选']
			,showSearch: true
			,height:300
			,width:600
			,id: 'detail_attr_list'
	})

     var data5 = <?php echo $json_goods_list;?>  //显示搜索框
             transfer.render({
                 elem: '#test5'
                 ,data: data5
                 ,title: ['全选', '全选']
                 ,showSearch: true
                 ,height:300
                 ,width:600
                 ,id: 'goods_attr_list'

             })
						
						
	  form.on('submit(formSub)', function(data){
		   
		  if($('#cat_list').length > 0){
			
			var checkData = tree.getChecked('cat_list');
			$('#cat_list_json').val(JSON.stringify(checkData))
		 }
		 
		 if($('#brand_list').length > 0){
		 	 var checkbrandData = tree.getChecked('brand_list');
			 $('#brand_list_json').val(JSON.stringify(checkbrandData))
		 }
		   
		   var ul = $("#test4").find("ul").eq(1);
			var input = $(ul).find("input");
			var saveArr = [];
			for(var i = 0; i < input.length; i++) {
				var inJson = {};
				
				inJson["title"] = input[i].title;
				inJson["value"] = input[i].value;
				saveArr.push(inJson);
			}
			json_data= JSON.stringify(saveArr)
		  
		  $('#detail_attr').val(json_data)



          var ul5 = $("#test5").find("ul").eq(1);
          var input5 = $(ul5).find("input");
          var saveArr5 = [];
          for(var i = 0; i < input5.length; i++) {
              var inJson5 = {};

              inJson5["title"] = input5[i].title;
              inJson5["value"] = input5[i].value;
              saveArr5.push(inJson5);
          }

          json_data5= JSON.stringify(saveArr5)

          $('#goods_attr').val(json_data5)


			
			$('.layui-form-pane').submit() 	
		
	  })
	  
	});

  
//上移
		function moveUp(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent(); 
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=0;i<index.length;i++){
				if(index.eq(i).index()!=0){
					 index.eq(i).prev().before(index.eq(i));
				}
			}   
					
		}
		
		//置顶
		function moveUpMax(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent(); 
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=index.length-1;i>=0;i--){
				do{
					index.eq(i).prev().before(index.eq(i));
				}while(index.eq(i).index()!=0)
			}       			
		}
		
		//下移
		function moveDown(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent(); 
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=index.length-1;i>=0;i--){
				if(index.eq(i).index()!=($("#"+dom+" ul li").length-1)){
					 index.eq(i).next().after(index.eq(i));
				}
			}       			
		}
		
		//置底
		function moveDownMax(dom) {
			//找到选中的li
			var index = $("#"+dom+" ul" ).eq(1).find('.layui-form-checked').parent(); 
			if(typeof(index[0]) == "undefined") {
				layer.msg("请选中后，再进行移位操作");
				return;
			}
			for(var i=0;i<index.length;i++){
				do{
					index.eq(i).next().after(index.eq(i));
				}while(index.eq(i).index()!=($("#"+dom+" ul").eq(1).find("li").length-1))
			}       			
		}

</script>



<script charset="utf-8" src="upload_video.js"></script>
<script charset="utf-8" src="upload_video2.js"></script>
<script charset="utf-8" src="asset/js/trans_pinyin.js?version=20231021"></script>
<?php include_once($_SERVER['DOCUMENT_ROOT']."/controller/common/module/footer.php");         // 引入通用的设置文件 ?>

</body>
</html>
